package com.gdth.bank.utils;

import java.util.ArrayList;
import java.util.List;

import com.gdth.bank.BankApplication;
import com.gdth.database.bean.TAppGncd;
import com.gdth.database.bean.TAppYh;
import com.gdth.model.ImageItem;

public class MenuUtil {
	/**
	 * 根据上级采集id获取下级菜单
	 * @param key
	 * @return
	 */
	public static List<ImageItem> getMenus(String key){
		TAppYh user = BankApplication.mInstance.getCurrentUser();
		
		List<ImageItem> items = new ArrayList<ImageItem>();
		
		List<TAppGncd> menus = user.getMenuList();
		if (menus == null)
			 return items;
		
		int xtszid = Integer.valueOf(key);
		for (TAppGncd mMenu :menus){
			String sjgnid = mMenu.getSjgnid();
			if (sjgnid != null &&  Integer.valueOf(sjgnid) == xtszid) {
				ImageItem sImageItem = new ImageItem();
				sImageItem.setGnlj(mMenu.getGnlj());
				sImageItem.setKey(mMenu.getGnid().toString());
				sImageItem.setValue(mMenu.getMc());
				sImageItem.setImg(mMenu.getTblj());
				sImageItem.setType(mMenu.getLb());
				
				items.add(sImageItem);
			}
		}
		
		return items;
	}
	
	/**
	 * 根据名称获取下级菜单
	 * @param name
	 * @return
	 */
	public static List<ImageItem> getMenuByName(String name){
		TAppYh user = BankApplication.mInstance.getCurrentUser();
		List<ImageItem> mList = new ArrayList<ImageItem>();
		
		List<TAppGncd> menus = user.getMenuList();
		if (menus == null)
			 return mList;
		
		int xtszid = 0;
		for (TAppGncd mMenu :menus){
			if (mMenu.getMc().equals(name)) {
				xtszid = mMenu.getGnid();
			}
		}
		for (TAppGncd mMenu :menus){
			String sjgnid = mMenu.getSjgnid();
			if (sjgnid != null &&  Integer.valueOf(sjgnid) == xtszid) {
				ImageItem sImageItem = new ImageItem();
				sImageItem.setGnlj(mMenu.getGnlj());
				sImageItem.setKey(mMenu.getGnid().toString());
				sImageItem.setValue(mMenu.getMc());
				sImageItem.setImg(mMenu.getTblj());
				sImageItem.setType(mMenu.getLb());
				
				mList.add(sImageItem);
			}
		}
		
		return mList;
	}
}
